<?php
/**
 * 代码原链接：	https://mp.weixin.qq.com/s?__biz=MzIxODQyNTU1MA==&amp;mid=2247484133&amp;idx=1&amp;sn=9d098517a4d7fc913d3657a706e23dbd&amp;chksm=97ebf344a09c7a5277707e75ecc1a4be743d23fc22ce2b038079acd3cbc6f2af4b8fa211e503&amp;scene=27&key=&ascene=1&uin=&devicetype=iMac+MacBookPro15%2C2+OSX+OSX+12.2.1+build(21D62)&version=13080712&nettype=WIFI&lang=zh_CN&countrycode=CN&fontScale=100
 */

interface Message
{
    public function send();
}

class BaiduYunMessage implements Message
{
    function send()
    {
        echo '百度云发送信息！';
    }
}

class AliYunMessage implements Message
{
    public function send()
    {
        echo '阿里云发送信息！';
    }
}

class JiguangMessage implements Message
{
    public function send()
    {
        echo '极光发送信息！';
    }
}

class MessageContext
{
    private $message;
    public function __construct(Message $msg)
    {
        $this->message = $msg;
    }
    public function SendMessage()
    {
        $this->message->send();
    }
}

$bdMsg = new BaiduYunMessage();
$msgCtx = new MessageContext($bdMsg);
$msgCtx->SendMessage();

$alMsg = new AliYunMessage();
$msgCtx = new MessageContext($alMsg);
$msgCtx->SendMessage();

$jgMsg = new JiguangMessage();
$msgCtx = new MessageContext($jgMsg);
$msgCtx->SendMessage();
